#pragma once 
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <string>
#include <iostream>
#include <jsoncpp/json/json.h>

#define TCP_PORT 17878  
#define UDP_PORT 17878
#define UDP_DATA_MAX_LEN 10240

using namespace std;
//注册的格式要求
//姓名、学校、密码
struct RegisterInfo
{
    RegisterInfo()
    {
        memset(name_,'\0',sizeof(name_));
        memset(school_,'\0',sizeof(school_));
        memset(passwd_,'\0',sizeof(passwd_));
    }
    char name_[20];
    char school_[20];
    char passwd_[20];
};


//登录的格式要求
//返回的id号,姓名
struct LoginInfo
{
    char name_[20];
    uint32_t id_;
    char passwd_[20];
};



//服务端回复客户端状态

struct ReplyInfo
{
    int resp_status_;
    uint32_t id_;
};


//标识是登录还是注册
enum ResqStatus 
{
    Register = 0,
    Login
};

//标识登录注册成功失败
enum Status 
{
    REGISTER_FAILED = 0,
    REGISTER_SUCCESS,
    LOGIN_FAILED,
    LOGIN_SUCCESS,
    ONLINE
};

class UdpMsg 
{
    public:
        UdpMsg()
        {

        }
        ~UdpMsg()
        {

        }
        //序列化 将对象转化为二进制数据
        //反序列化 将二进制数据转化为对象
        void serialize(string* msg)
        {
            Json::Value json_msg;

            json_msg["name"] = name_;
            json_msg["school"] = school_;
            json_msg["id"] = id_;
            json_msg["msg"] = msg_;

            Json::FastWriter writer;

            *msg = writer.write(json_msg);
        }

        void deserialize(const string& msg)
        {
            Json::Reader reader;
            Json::Value val;
            reader.parse(msg,val);

            name_ = val["name"].asString();
            school_ = val["school"].asString();
            id_ = val["id"].asUInt();
            msg_ = val["msg"].asString();
        }
        
    public:
        string name_;
        string school_;
        uint32_t id_;
        string msg_;
};



